package mqtt;

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttMessage;

public class Main {

    public static void main(String[] args) {
        MQTTClient mqttClient = new MQTTClient();
        // ReconnectMqttCallback 重连的回调函数
        mqttClient.connect(new ReconnectMqttCallback(
                mqttClient.getOptions(),mqttClient.getClient(),mqttClient.getTopic(),mqttClient.getQos()) {
            @Override
            public void messageArrived(String s, MqttMessage message) throws Exception {
                System.out.println("Message arrived: " + new String(message.getPayload()));
            }

            @Override
            public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
                System.out.println("Delivery complete");
            }
        });
        mqttClient.publish("你好666");
        mqttClient.disconnect();// 关闭连接
        mqttClient.close();// 关闭客户端
    }

}
